<template>
	<view class="title">提现至</view>

	<view class="bank-card" @click="show = true">
		<image :src="columnsLod[select].bank_json_data.bank_logo" mode=""></image>
		<view class="tit">{{columnsLod[select].bank_json_data.bank_title}}</view>
		<up-icon name="arrow-right" color="#BABABA" size="15"></up-icon>
	</view>

	<view class="title">提现金额</view>
	<view class="money">
		<view class="input">
			<view>¥</view>
			<up-input
				placeholder="请输入金额"
				border="none"
				type="number"
				v-model="price"></up-input>
			<!-- <view @click="">全部</view> -->
		</view>
		<view class="money-usable">余额¥{{userinfo.balance}}</view>
	</view>

	<view class="btn" @click="throttle(submit)">立即提现</view>
	<!-- <view class="tips">温馨提示：提现最低额度为100元</view> -->

	<up-picker
		:show="show"
		:columns="columns"
		@cancel="show = false"
		@confirm="confirm"></up-picker>
</template>

<script setup>
	import { throttle } from '@/uni_modules/uview-plus';
	import { onLoad } from '@dcloudio/uni-app'
	import { ref, reactive } from 'vue';
	import api from '../../api/api';
	import { useCounterStore } from '../../stores/user';
	import { storeToRefs } from 'pinia'
	const user = useCounterStore()
	const { userinfo } = storeToRefs(user)

	onLoad(() => {
		user_banks()
	})

	function user_banks() {
		api.user.user_banks()
			.then(res => {
				res.data.forEach(x => {
					x.bank_json_data = JSON.parse(x.bank_json_data)
				})
				res.data.forEach(x => {
					x.bank_json_data.bank_title += `(${x.card_no.slice(-5)})`
				})
				columns[0] = res.data.map(x => x.bank_json_data.bank_title)
				Object.assign(columnsLod, res.data)
			})
	}


	const show = ref(false);
	const columnsLod = reactive([])
	const columns = reactive([
		[]
	]);

	function confirm(e) {
		select.value = e.indexs[0]
		show.value = false
	}

	const select = ref(0)
	const price = ref('')

	function submit() {
		if (!price.value) return uni.$showMsg("请输入金额")
		api.user.user_create_widthwal({
			price: price.value,
			user_card_id: columnsLod[select.value].user_bank_id
		}).then(res => {
			uni.$showMsg("提交成功")
			setTimeout(() => {
				uni.navigateBack({
					delta: 2
				})
			}, 1000)
		})
	}
</script>

<style lang="scss">
	.title {
		padding: 32rpx;
		font-weight: 600;
		font-size: 32rpx;
		color: #333333;
	}

	.bank-card {
		width: 686rpx;
		height: 100rpx;
		background: #FFFFFF;
		border-radius: 12rpx;
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.tit {
			width: 85%;
			line-height: 1;
		}

		image {
			width: 36rpx;
			height: 36rpx;
			display: block;
		}
	}

	.money {
		padding: 0 32rpx;
		width: 686rpx;
		background: #FFFFFF;
		border-radius: 12rpx;
		margin: 32rpx auto 0;

		.input {
			font-weight: 600;
			font-size: 48rpx;
			color: #333333;
			display: flex;
			align-items: center;
			padding-bottom: 20rpx;
			border-bottom: 1px solid #e2e2e2;

			>view:nth-child(1) {
				margin-right: 20rpx;
			}

			>view:nth-child(3) {
				font-weight: 400;
				font-size: 28rpx;
				color: #F6941D;
				margin-left: 20rpx;
			}
		}

		.money-usable {
			font-weight: 400;
			font-size: 28rpx;
			color: #999999;
			margin-top: 20rpx;
		}
	}

	.btn {
		width: 686rpx;
		height: 100rpx;
		line-height: 100rpx;
		background: #F6941D;
		border-radius: 12rpx;
		font-weight: 600;
		font-size: 28rpx;
		color: #FFFFFF;
		margin: 0 auto;
		margin-top: 64rpx;
		text-align: center;
	}

	.tips {
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		text-align: center;
		margin-top: 20rpx;
	}
</style>